var express = require('express');
var router = express.Router();


var sqlHandler = require('../service/test.js');

var users = [
	{name:'王喜田',age:18,sex:'男'},
	{name:'李四',age:29,sex:'男'},
	{name:'老王',age:34,sex:'男'},
	{name:'二狗',age:14,sex:'男'},
	{name:'春生',age:25,sex:'男'},
	{name:'建国',age:88,sex:'男'},
];

/* GET users listing. */
router.get('/', function(req, res, next) {
  // res.send('好好学习天天向上');
  res.json(users);
});

router.get('/fans', function(req, res, next) {
  // res.send('好好学习天天向上');
  res.render('linfans',{title:"林姐姐粉丝群",
  	data:users});
});

router.get('/add_book_view', 
	function(req, res, next) {
  res.render('add_book',{});
});

router.post('/add_book_handler', 
	function(req, res, next) {
	// var sql = `insert into mm_books(b_name,b_price) 
	// values('${req.body.b_name}',${req.body.b_price})`;	
 //  // res.render('add_book',{});
	//   sqlHandler.update(sql,function (resule) {
	//   	res.send("搞完了，去看看吧！");
	//   });

	msql.query(`insert into mm_books(b_name,b_price) values(?,?)`,
		[req.body.b_name,req.body.b_price],
		function (argument) {
			res.send("搞完了，去看看吧！");
		})
});

module.exports = router;
